package com.tgr.shortLink.admin.toolkit;

import lombok.Data;
import org.graalvm.polyglot.io.ByteSequence;

import java.security.SecureRandom;

/**
 * 描述：分组ID随机生成器
 * 作者：小陶不慌张
 * 文件：RandomGenerator
 * 日期：2024/1/14 1:25
 */

@Data
public class RandomGenerator {
    private static final String CHARACTERS = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
    private static final SecureRandom RANDOM= new SecureRandom();

    public static String generateRandom(){
        return generateRandom(6);
    }

    public static String generateRandom(int length) {
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int randomIndex = RANDOM.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(randomIndex));
        }
        return sb.toString();
    }
}
